<?php
define('IN_TG','photo_add_dir');
define('IN_JS','photo_add_dir');
define('SCRIPT','photo_add_dir');
require("includes/common.inc.php");

//登录状态
session_start();
_check_login();
///增加目录操作
if(!empty($_POST))
{
	//如果是私密的情况下 判断密码
	////密码加密
	require('includes/check.func.php');
	$_dir['name']=_check_dir_name($_POST['name'],5,20);
	$_dir['type']=$_POST['type'];
	$_dir['password']=$_dir['type']==1?_check_dir_password($_POST['password'],6):'';
	$_dir['content']=$_POST['content'];
	//服务器目录地址 创建目录
	$path='photo/'.time();
	$r=mkdir($path,0700);
	if($r)
	{
		//保存到数据库
		$sql = "insert into tg_dir(tg_name,tg_type,tg_password,tg_content,tg_dir,tg_date,tg_username) VALUES ('{$_dir['name']}',{$_dir['type']},'{$_dir['password']}','{$_dir['content']}','{$path}',NOW(),'{$_COOKIE['username']}')";
		//跳转到 post
		$res = _query($sql);
		if($res){
			_close();
			header('location:photo.php');
		} else {
			_close();
			_alert_back('添加相册目录失败！');
		}
	}
	else
	{
		_alert_back('相册创建目录失败！');
	}
}
require('header.php');
?>
<div id="photo">
	<h2>添加相册目录</h2>
	<form method="post" action="photo_add_dir.php">
	<dl>
		<dd>相册名称：<input type="text" name="name" class="text" /></dd>
		<dd>相册类型：<input type="radio" name="type" value="0" checked="checked" /> 公开 <input type="radio" name="type" value="1" /> 私密</dd>
		<dd id="pass">相册密码：<input type="password" name="password" class="text" /></dd>
		<dd>相册描述：<textarea name="content"></textarea></dd>
		<dd><input type="submit" class="submit" value="添加目录" /></dd>
	</dl>
	</form>
</div>
<?php
require('includes/footer.inc.php');
?>
